package backend.model.other;

import backend.model.base.DBModel;
import shared.util.CalendarUtils;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import javax.persistence.*;
import java.util.Date;

@NamedQueries({ @NamedQuery(name = "findAllLegalHolidays", query = "from LegalHoliday"),
                @NamedQuery(name = "findLegalHolidayByDate", query = "from LegalHoliday where date = :date")})
@Entity
@Table(name = "legal_holiday")
public class LegalHoliday extends DBModel {

    @Id
    @GeneratedValue
    @Column(name = "id")
    private int id;

    @Column(name = "year")
    private int year;

    @Column(name = "date")
    private Date date;

    @Column(name = "description")
    private String description;

    @Override
    public int getId() {
        return id;
    }

    @Override
    public String getDisplayLabel() {
        return CalendarUtils.formatDate(getDate()) + " (" + getDescription() + ")";
    }

    @Override
    public boolean getIsActive() {
        return true;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public int compareTo(Object object) {
        return this.getDate().compareTo(((LegalHoliday)object).getDate());
    }
}
